package net.homeftp.heimo;

import java.util.ArrayList;
import java.util.List;

import net.homeftp.heimo.adaptor.ListItemAdaptor;
import net.homeftp.heimo.model.ListItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class ListActivity extends Activity implements OnItemClickListener {
	private ListView listView;
	private ListItemAdaptor adp;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_layout);

		List<ListItem> list = new ArrayList<ListItem>();
		listView = (ListView) this.findViewById(R.id.listView);
		adp = new ListItemAdaptor(this, list);
		listView.setAdapter(adp);
		listView.setOnItemClickListener(this);
		fnLoad(listView);
	}

	public void fnLoad(View v) {
		for (int i = 0; i < 50; i++) {
			ListItem li = new ListItem();
			li.setImageID(R.drawable.ic_launcher);
			li.setTitle("Item No : " + i);
			li.setDescription("This is testing item,\n with item no :" + i);
			li.setRemark("$" + (i * 25));
			adp.addItems(li);
		}
		adp.update();
	}

	public void fnRemove(View v) {
		adp.removeAll();
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Toast.makeText(ListActivity.this, "Selected : "+position, Toast.LENGTH_LONG).show();
		adp.setSelectedPosition(position);
	}
}
